package com.kinpoway.web.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;
// @Component  //直接通过注册组件的形式注册一个Filter,不能设置只对某些路径起作用。对所有的请求都起作用。
public class TimeFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("time filter init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("time filter Started");
        long start = new Date().getTime();
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("time filter finish " + (new Date().getTime() - start));

    }

    @Override
    public void destroy() {
        System.out.println("time filter destroy");

    }
}
